const { merge } = require('webpack-merge');
const common = require('./webpack.common');
// 请只在生产环境下使用 CSS 提取，这将便于你在开发环境下进行热重载。
var MiniCssExtractPlugin = require('mini-css-extract-plugin')
//压缩css代码
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");


const config = merge(common, {
  mode: 'production',
  module: {
    rules: [
      {
        //使用正则匹配两个
        test: /\.(le|c)ss$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          "postcss-loader",  //先添加前缀
          'less-loader',
        ]
      },
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: "static/css/[name].[hash].css", //通过名字添加一层路径
    }),
    //添加css压缩插件
    new OptimizeCSSAssetsPlugin({})
  ]
});

module.exports = config